package com.briup.srms.sms.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.srms.sms.bean.Employee;
import com.briup.srms.sms.bean.extend.EmployeeExtend;
import com.briup.srms.sms.service.IEmployeeService;
import com.briup.srms.sms.vm.DirectionEmployees;
import com.jacky.base.utils.Message;
import com.jacky.base.utils.MessageUtil;
import com.jacky.base.utils.PageVM;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @program: sms
 * @description: 员工控制器类
 * @author: jacky
 * @create: 2021-1-5 14:41
 **/
@Api(description="企业员工相关接口")
@Validated
@RestController
@RequestMapping("/employee")
public class EmployeeController {

	@Autowired
	private IEmployeeService employeeService;

	@ApiOperation(value = "根据账号获取员工信息")
	@GetMapping("findByAccountId")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "账号ID", required = true, paramType = "query"),
	})
	public Message findByAccountId(@NotNull long id) {
        System.out.println("【findEmployeeByAccountId】");
		Employee employee = employeeService.findByAccountId(id);
		return MessageUtil.success(employee);
	}

	@ApiOperation(value = "分页多条件获取员工信息")
	@GetMapping("pageQuery")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "当前页", required = true, paramType = "query"),
		@ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"),
		@ApiImplicitParam(name = "deptId", value = "部门编号", paramType = "query"),
		@ApiImplicitParam(name = "realname", value = "姓名",  paramType = "query"),
		@ApiImplicitParam(name = "status", value = "状态", paramType = "query"),
		@ApiImplicitParam(name = "directionId", value = "方向编号", paramType = "query")
	})
	public Message pageQuery(int page, int pageSize,Long deptId,String realname,String status,Long directionId) {
        System.out.println("【pageQueryEmployee】");
		PageVM<EmployeeExtend> pageVM = employeeService.pageQuery(page, pageSize,deptId,realname,status,directionId);
		return MessageUtil.success(pageVM);
	}

	@ApiOperation(value = "通过id删除员工信息")
	@GetMapping("deleteById")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query"),
	})
	public Message deleteById(@NotNull long id) {
		employeeService.deleteById(id);
		return MessageUtil.success("删除成功!");
	}

	@ApiOperation(value = "保存或更新班主任信息")
	@PostMapping("saveOrUpdate")
	public Message saveOrUpdate(Employee employee) {
		// 教管部班主任角色编号
		long roleId = 8l;
		employeeService.saveOrUpdate(employee,roleId);
		return MessageUtil.success("操作成功！");
	}

	@ApiOperation(value = "保存或更新讲师信息")
	@PostMapping("saveOrUpdateProfessor")
	public Message saveOrUpdateProfessor(Employee employee) {
		// 教学部讲师角色编号
		long roleId = 12l;
		employeeService.saveOrUpdate(employee,roleId);
		return MessageUtil.success("操作成功！");
	}

	@ApiOperation(value = "保存或更新市场咨询师信息")
	@PostMapping("saveOrUpdateCounselor")
	public Message saveOrUpdateCounselor(Employee employee) {
		// 教学部讲师角色编号
		long roleId = 9l;
		employeeService.saveOrUpdate(employee,roleId);
		return MessageUtil.success("操作成功！");
	}

	@ApiOperation(value = "保存或更就业部导师信息")
	@PostMapping("saveOrUpdateEmployment")
	public Message saveOrUpdateEmployment (Employee employee) {
		// 就业部老师角色编号
		long roleId = 14l;
		employeeService.saveOrUpdate(employee,roleId);
		return MessageUtil.success("操作成功！");
	}

	@ApiOperation(value = "更新员工信息")
	@PostMapping("alterEmployment")
	public Message alterEmployment (Employee employee) {
		employeeService.alter(employee);
		return MessageUtil.success("更新成功！");
	}

	@ApiOperation(value = "员工离职")
	@GetMapping("leaveBriup")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "employeeId", value = "员工ID", required = true, paramType = "query"),
	})
	public Message leaveBriup(long employeeId) {
		employeeService.leaveBriup(employeeId);
		return MessageUtil.success("离职成功");
	}

	@ApiOperation(value = "查询方向员工树")
	@GetMapping("queryDirectionEmployees")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "directionId", value = "方向编号", paramType = "query"),
	})
	public Message queryDirectionEmployees(Long directionId) {
        System.out.println("【queryDirectionEmployees】");
		List<DirectionEmployees> list  = employeeService.queryDirectionEmployees(directionId,"正常");
		return MessageUtil.success(list);
	}


}
